<%@ page import="knu.product" %>
<%--
  Created by IntelliJ IDEA.
  User: Ray
  Date: 2014-12-10
  Time: 오전 11:04
  To change this template use File | Settings | File Templates.
--%>

<%
  Cookie[] cookies = request.getCookies();
  String pnlist=new String();
  if(cookies!=null){
    for(Cookie cookie : cookies){
      if(cookie.getName().equals("pnlist")){
        pnlist=cookie.getValue();
        break;
      }
    }
  }
%>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
  <title></title>
</head>
<body>
<h1>상품목록</h1>
<%
  product dr=new product("드라이기",12000);
  product sp=new product("스피커",50000);
  product ba=new product("가방",35000);
  product[] pro=new product[]{dr,sp,ba};
%>
<table border="1" cellpadding="5">
  <thead>
  <tr>
    <td>번호</td>
    <td>품목</td>
    <td>가격</td>
    <td>장바구니</td>
  </tr>
  </thead>

  </tr>
  <td>1</td>
  <td><%=dr.name%></td>
  <td><%=dr.price%></td>
  <td>
    <form action="/AppendPro" method="post">
      <input type="hidden" name="pn" value="1"/>
      <input type="submit" value="담기"/>
    </form>
  </td>

  </tr>
  <td>2</td>
  <td><%=sp.name%></td>
  <td><%=sp.price%></td>
  <td>
    <form action="/AppendPro" method="post">
      <input type="hidden" name="pn" value="2"/>
      <input type="submit" value="담기"/>
    </form>
  </td>

  </tr>
  <td>3</td>
  <td><%=ba.name%></td>
  <td><%=ba.price%></td>
  <td>
    <form action="/AppendPro" method="post">
      <input type="hidden" name="pn" value="3"/>
      <input type="submit" value="담기"/>
    </form>
  </td>

</table>
<h1>장바구니</h1>





<table border="1" cellpadding="5" id="pntable">
  <thead>
  <tr>
    <td>번호</td>
    <td>품목</td>
    <td>가격</td>
    <td>
      <form action="/DeletePro" method="post">
        <input type="hidden" name="pn" value="-1"/>
        <input type="submit" value="전부삭제"/>
      </form>
      <%=pnlist%>
    </td>
  </tr>
  </thead>
  <tbody>
  <%
    String[] pnli=new String[0];
    for (Cookie cookie : cookies) {
      if (cookie.getName().equals("pnlist")) {
        String pn=cookie.getValue();
        pnli=pn.split(" ");
        break;
      }
    }
    int i=0;%>
  <%
    if(pnli.length!=0){
      for(String pns : pnli){

  %>
  <tr>
    <td><%=i+1%></td>
    <td><%=pro[Integer.parseInt(pns)-1].name%></td>
    <td><%=pro[Integer.parseInt(pns)-1].price%></td>
    <td>
      <form action="/DeletePro" method="post">
        <input type="hidden" name="pn" value="<%=i%>" />
        <input type="submit" value="빼기"/>
      </form>

    </td>
  </tr>

  </tbody>
  <%
        i++; }
    }
  %>

</table>

</body>
</html>
